// views/index/shop/germanyinsurance/otherinsurance/otnerinsurancedetail/carecampus/index.js
var BASE_URL = getApp().globalData.BASE_URL

Page({

  /**
   * 页面的初始数据
   */
  data: {
    minDate: new Date(1950, 0, 1).getTime(),
    opendiqupop: false,
    showdatepop: false,
    currentDate: new Date().getTime(),
    nowtime: "",
    moon: 12,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    born: "yyyy/mm/日",
    flag: "本科生",
    cate: "产品介绍",
    price: 29
  },

  //改变中间的标题
  change_nav: function (e) {
    this.setData({
      cate: e.currentTarget.dataset.cate
    })
  },
  onChange(event) {
    this.setData({
      moon: event.detail
    })
  },
  //改变留德目的
  change_flag: function (e) {
    this.setData({
      flag: e.currentTarget.dataset.flag
    })
  },


  //打开时间pop
  opendatepop: function () {
    this.setData({
      showdatepop: true
    })
  },
  //关闭时间pop
  onClose: function () {
    this.setData({
      showdatepop: false,
      opendiqupop: false
    })
  },

  //切换时间
  getColumnValue(event) {
    console.log(event)
    this.setData({
      nowtime: event.detail,
    });
  },

  //确定时间
  change_date: function () {
    this.setData({
      showdatepop: false,
      born: this.changeTime(this.data.nowtime)
    })
  },



  placeorder: function () {
    var userinfo = wx.getStorageSync("USER")
    var _this = this
    wx.request({
      url: `${BASE_URL}/baoxian/zhuannew`,
      method: "POST",
      data: {
        uid: userinfo.id,
        type: 'xiaochengxv',
        mudi: _this.data.flag,
        ming_bao : 'Care Student',
        amount : 29,
        qty_item_1:12
      },
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      success(res) {
        console.log(res)
        wx.navigateTo({
          url: `../../shiliinsurance/index?id=${res.data.id}&price=29`
        })
      }
    })

  },












  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 时间戳转换
  changeTime(time) {
    if (time) {
      var oDate = new Date(time * 1),
        oYear = oDate.getFullYear(),
        oMonth = oDate.getMonth() + 1,
        oDay = oDate.getDate(),
        oTime = oYear + "/" + this.getBz(oMonth) + "/" + this.getBz(oDay)
      return oTime;
    } else {
      return "";
    }
  },
  // 补0
  getBz(num) {
    if (parseInt(num) < 10) {
      num = "0" + num;
    }
    return num;
  },
})